package com.hk.aefz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hk.aefz.po.UserInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author 阿尔法哲
 * @since 2020-07-21
 */
public interface UserInfoMapper extends BaseMapper<UserInfo> {

    @ApiOperation("通过账户id查询用户")
    @SelectProvider(type = UserInfoProvider.class,method = "selectByIds")
    List<UserInfo> selectByIds(@Param("aids") List<Integer> aids);

    class UserInfoProvider {
        public String selectByIds(Map map) {
            List<Integer> list = (List<Integer>) map.get("aids");
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT * FROM user_info WHERE aid IN(");
            MessageFormat mf = new MessageFormat("#'{'aids[{0}]}");
            for (int i = 0; i < list.size(); i++) {
                sb.append(mf.format(new Object[]{i}));
                if (i < list.size() - 1) {
                    sb.append(",");
                }
            }
            sb.append(")");
            return sb.toString();
        }
    }

}
